/**
 * Created by wzh on 2016/7/11.
 */
'use strict'
swan_pc
    .factory('OppInfo', function ($resource, DateUtils) {
        return $resource('/api/userOpportunitys/:infoid', {infoid:'@infoid'}, {
            'query': { method: 'GET', isArray: true},
            'queryAll': {
                method: 'GET',
                transformResponse: function (data) {
                    data = angular.fromJson(data);
                    //data.baseInfo.birthDate = DateUtils.convertLocaleDateFromServer(data.baseInfo.birthDate);
                    _.forEach(data.opportunityDates,function(item){
                        item.date=DateUtils.convertLocaleDateFromServer(item.date)
                    })
                    return data;
                }
            },
            'update': {
                method: 'PUT',
                transformRequest: function (data) {
                    _.forEach(data.opportunityDates,function(item){
                        item.date=DateUtils.convertLocaleDateToServer(item.date)
                    })
                    //data.birthDate = DateUtils.convertLocaleDateToServer(data.birthDate);
                    return angular.toJson(data);
                }
            },
            'save': {
                method: 'POST',
                transformRequest: function (data) {
                    for(var i=0;i<7;i++) {
                        //data.opportunityDates[i].date = DateUtils.convertLocaleDateToServer(data.opportunityDates[i].date);
                    }
                    return angular.toJson(data);
                }
            },
            'delete':{
                method:'DELETE'
            },
            'linkup':{
                method:'GET',
                url:"/api/userOpportunitys/:infoid/linkUp",
            },
            'linkDown':{
                method:'GET',
                url:"/api/userOpportunitys/linkDown",
            },
            'breakLink':{
                method:'GET',
                url:"/api/userOpportunitys/:infoid/breakDownByUser",
            },
        });
    });